package action;

import java.util.ArrayList;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import model.bean.Members;
import model.bo.AccountManagerBO;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import form.UserManagerForm;

public class UserManagerAction extends Action {

	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		UserManagerForm userManagerForm = (UserManagerForm) form;
		AccountManagerBO accountManagerBO = new AccountManagerBO();
		ArrayList<Members> listUser = new ArrayList<Members>();
		listUser = accountManagerBO.GetListUser();
		String userName = userManagerForm.getUserName();
		String password = userManagerForm.getPassword();
		
		if ("Delete".equals(userManagerForm.getBtnDelete())) {
			accountManagerBO.DeleteUser(userName);
		}

		if ("Reset Password".equals(userManagerForm.getBtnSubmit())) {
			accountManagerBO.ResetPassword(userName, password);
		}
		userManagerForm.setListUser(listUser);
		request.setAttribute("listUser", listUser);
		return mapping.findForward("OK");
	}
}
